//
//  SCNBorrowHeaderView.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/3/27.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

class SCNBorrowHeaderView: UIView {
    
    
    var getCodeBlock: ((String) -> Void)?
    
    
    // 这里用了绝对坐标 不好看
    lazy var typeTF: SCNBorrowHeadTextField = {
       let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 65, width: SCNConstants.SCREENWIDTH - 40, height: 35), title: "贷款类型", placeholder: "请选择贷款类型", action: true, tag: 1)
        
        return textField
    }()
    lazy var nameTF: SCNBorrowHeadTextField = {
        let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 106, width: SCNConstants.SCREENWIDTH - 40, height: 35), title: "姓名", placeholder: "请输入真实姓名", action: false, tag: 2)
        
        return textField
    }()
    lazy var cardIDTF: SCNBorrowHeadTextField = {
        let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 147, width: SCNConstants.SCREENWIDTH - 40, height: 35), title: "身份证号", placeholder: "请输入身份证号", action: false, tag: 3)
        
        return textField
    }()
    lazy var phoneTF: SCNBorrowHeadTextField = {
        let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 188, width: SCNConstants.SCREENWIDTH - 40, height: 35), title: "手机号", placeholder: "请输入手机号", action: false, tag: 4)
        
        return textField
    }()
    lazy var moneyTF: SCNBorrowHeadTextField = {
        let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 229, width: SCNConstants.SCREENWIDTH - 40, height: 35), title: "借款金额", placeholder: "请输入借款金额", action: false, tag: 5)
        
        return textField
    }()
    lazy var timeTF: SCNBorrowHeadTextField = {
        let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 270, width: SCNConstants.SCREENWIDTH - 40, height: 35), title: "借款期限", placeholder: "请选择借款期限", action: true, tag: 6)
        
        return textField
    }()
    lazy var codeTF: SCNBorrowHeadTextField = {
        let textField = SCNBorrowHeadTextField.init(frame: CGRect(x: 20, y: 311, width: SCNConstants.SCREENWIDTH - 120, height: 35), title: "验证码", placeholder: "请输入验证码", action: false, tag: 7)
        
        return textField
    }()
    
    lazy var codeBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.frame = CGRect(x: SCNConstants.SCREENWIDTH - 95, y: 311, width: 75, height: 35)
        btn.backgroundColor = SCNConstants.colorWithHexString("49EA98")
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 13.0)
        btn.setTitle("获取验证码", for: .normal)
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.layer.cornerRadius = 5.0
        btn.layer.masksToBounds = true
        btn.addTarget(self, action: #selector(self.getCodeAction), for: .touchUpInside)
        
        return btn
    }()
    
    lazy var submitBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.bounds = CGRect(x: 0, y: 0, width: 140, height: 36)
        btn.center = CGPoint(x: SCNConstants.SCREENWIDTH/2, y: 384)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 18.0)
        btn.setTitle("提交申请", for: .normal)
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.layer.cornerRadius = 18.0
        btn.layer.masksToBounds = true
        btn.layer.borderColor = UIColor.white.cgColor
        btn.layer.borderWidth = 1.0
        btn.addTarget(self, action: #selector(self.submitAction), for: .touchUpInside)
        
        return btn

    }()
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = SCNConstants.rootBackgroundColor
        
        configurationUI()
        
    }
    
    func configurationUI() {
        
        let imgView = UIImageView(frame: CGRect(x: 20, y: 15, width: SCNConstants.SCREENWIDTH - 40, height: 34))
        imgView.image = UIImage(named: "icon_wenzi")
        
        
        self.addSubview(imgView)
        self.addSubview(typeTF)
        self.addSubview(nameTF)
        self.addSubview(cardIDTF)
        self.addSubview(phoneTF)
        self.addSubview(moneyTF)
        self.addSubview(timeTF)
        self.addSubview(codeTF)
        self.addSubview(codeBtn)
        self.addSubview(submitBtn)
    }
    
    func getCodeAction() {
        // 获取验证码
        if let tmp = phoneTF.text {
            getCodeBlock?(tmp)
        }
        
    }
    func submitAction() {
        // 提交申请
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}


